package com.ruoyi.project.oms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.oms.domain.OmsAftersale;
import com.ruoyi.db.oms.domain.query.OmsAftersaleQueryVo;
import com.ruoyi.project.oms.service.OmsAftersaleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 售后Controller
 *
 * @author yfy
 * @date 2020-04-25
 */
@Api(tags="oms管理：售后管理")
@RestController
@RequestMapping("/oms/aftersale")
public class OmsAftersaleController extends BaseController
{
    @Autowired
    private OmsAftersaleService omsAftersaleService;

    @ApiOperation("查询售后列表")
    @PreAuthorize("@ss.hasPermi('oms:aftersale:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsAftersaleQueryVo omsAftersaleQueryVo)
    {
        startPage();
        List<OmsAftersale> list = omsAftersaleService.selectOmsAftersaleList(omsAftersaleQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出售后列表")
    @Log(title = "售后", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('oms:aftersale:export')")
    @GetMapping("/export")
    public AjaxResult export(OmsAftersaleQueryVo omsAftersaleQueryVo)
    {
        List<OmsAftersale> list = omsAftersaleService.selectOmsAftersaleList(omsAftersaleQueryVo);
        ExcelUtil<OmsAftersale> util = new ExcelUtil<OmsAftersale>(OmsAftersale.class);
        return util.exportExcel(list, "aftersale");
    }

    @ApiOperation("获取售后详细信息")
    @Log(title = "售后", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oms:aftersale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(omsAftersaleService.selectOmsAftersaleById(id));
    }

    @ApiOperation("新增售后")
    @Log(title = "售后", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('oms:aftersale:add')")
    @PostMapping
    public AjaxResult add(@RequestBody OmsAftersale omsAftersale)
    {
        return toAjax(omsAftersaleService.insertOmsAftersale(omsAftersale));
    }

    @ApiOperation("修改售后")
    @Log(title = "售后", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('oms:aftersale:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody OmsAftersale omsAftersale)
    {
        return toAjax(omsAftersaleService.updateOmsAftersale(omsAftersale));
    }

    @ApiOperation("删除售后")
    @Log(title = "售后", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('oms:aftersale:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsAftersaleService.deleteOmsAftersaleByIds(ids));
    }
}
